package demo_0402.homework;

public class T2 {
    public static void main(String[] args) {
        /*协议：http
        主机: baidu.com
        端口：8080
        路径：system/login.jsp
        参数：user=admin&password=123
        引用：top
        协议：http*/
        String url = "https://baidu.com:8080/system/login.jsp?user=admin&password=123#top";

        //处理协议
        int xyEnd = url.indexOf("://");
        String xy = url.substring(0, xyEnd);
        System.out.println("协议：" + xy);

        //处理主机
        String newUrl = url.substring(xyEnd + 3);
        int zjEnd = newUrl.indexOf(':');
        System.out.println("主机：" + newUrl.substring(0, zjEnd));

        //处理端口
        newUrl = newUrl.substring(zjEnd + 1);
        int dkEnd = newUrl.indexOf('/');
        System.out.println("端口：" + newUrl.substring(0, dkEnd));

        //处理路径
        newUrl = newUrl.substring(dkEnd + 1);
        int ljEnd = newUrl.indexOf('?');
        System.out.println("路径：" + newUrl.substring(0, ljEnd));

        //处理参数
        newUrl = newUrl.substring(ljEnd + 1);
        int csEnd = newUrl.indexOf('#');
        System.out.println("参数：" + newUrl.substring(0, csEnd));

        //处理引用
        newUrl = newUrl.substring(csEnd + 1);
        System.out.println("引用：" + newUrl);
    }
}
